<template>
	<view>
		<view>
			<navitop>
				<i class="iconfont" slot="left-slot" @click="outlot">&#xe667;</i>
				<span slot="center-slot">设备列表</span>
				<i class="iconfont icon-youcecaidan" slot="right-slot" @click="Bubble(data)"></i>
			</navitop>
		</view>
		<view :style="'padding-top:' + nv_height + ';'"  class='public_other'>
			<div class="out_bottom">
				<div class="out_dologin" v-for="(item,index) in dataSorce" >
					<view class="out_txt" @click="device_edit(item.id)">
						{{item.name}}
					</view>
					<view class="out_switch">
						<switch name="switch" @click="switch_cancel(item)" v-if="item.status == 1" checked />
						<switch name="switch" @click="switch_deactivate(item)" v-else />
					</view>
				</div>
			</div>
		</view>
		
		<!-- 气泡弹窗 -->
		 <chunLei-popups v-model="value" :popData="data" @tapPopup="tapPopup" :x="345" :y="95" placement="top-end">
		 </chunLei-popups>
	</view>
</template>

<script>
import navitop from '@/components/common/navi-top'
import {pdapageList,pdasave} from '@/common/api/my/subpage.js'
import chunLeiPopups from "@/components/chunLei-popups/chunLei-popups";
export default {
	components:{
		navitop
	},
	data(){
		return {
			nv_height: '',
			dataSorce: [],
			value: false,
			data: [		// 气泡弹窗数据
				{title:'新增',code:'add',icon:'icon-tianjiaadd143'},
			],
		}
	},
	mounted() {
		this.nv_height = uni.getSystemInfoSync().statusBarHeight + 65 + 'px';
		
		this.data_list();
	},
	methods: {
		Bubble(){
			this.value = !this.value;
		},
		tapPopup(val){
			uni.navigateTo({
				url: '/pages/my/subpage/subpage_add'
			})
		},
		
		// 修改
		device_edit(val){
			uni.navigateTo({
				url:'/pages/my/subpage/subpage_edit?id=' + val
			})
		},
		
		// 关闭
		switch_cancel(val) {
			uni.showLoading({
				title: '停用中。。。'
			})
			val.status = 0;
			pdasave(val).then(item => {
				if(item.code == 200){
					uni.hideLoading();
					uni.showToast({
						title: '已停用！',
						icon: 'none'
					})
					this.data_list();
				}
			})
		},
		//启用
		switch_deactivate(val) {
			uni.showLoading({
				title: '启用中。。。'
			})
			val.status = 1;
			pdasave(val).then(item => {
				if(item.code == 200){
					uni.hideLoading();
					uni.showToast({
						title: '启用成功！',
						icon: 'none'
					})
					this.data_list();
				}
			})
		},
		//上一页
		outlot(){
			uni.redirectTo({
				url: '/pages/my/subpage/set_list'
			})
			// uni.switchTab({
			// 	url: '/pages/my/my'
			// })
		},
		// 个人信息
		set_security(){
			uni.redirectTo({
				url:'/components/user-sz/user-sz'
			})
		},
		// 获取pda型号列表
		data_list(){
			pdapageList().then(item => {
				if(item.code == 200){
					console.log(item)
					this.dataSorce = item.data.records;
				}
			})
		}
	}
}
</script>

<style scoped lang='scss'>
 @import '@/static/css/common/public_css.scss';
 .out_bottom{
	 width: 100%;
 }
 .out_dologin {
	 border-radius: 4px;
	 border-bottom: 1px solid #cacaca;
	 height: 90rpx;
	 line-height: 90rpx;
	 margin: auto;
	 background-color: #fff;
	 width: 95%;
	 display: flex;
 }
 
 .out_txt {
	 width: 75%;
	 padding: 0 0 0 30rpx;
 }
 
 .out_switch {
	 float: right;
 }
</style>
